package commMysql

import "gorm.io/gorm"

func FindFileByUuidsByCustoms[T any](uuids []string, db *gorm.DB, Customs ...func(db *gorm.DB) error) ([]T, error) {
	var (
		data []T
	)
	tx := db.Begin()
	err := tx.Where("uuid IN ? AND is_del=?", uuids, 0).Find(&data).Error
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()
	}
	for _, custom := range Customs {
		err := custom(tx)
		if err != nil {
			return data, err
		}
	}
	return data, err
}
func FindFileByUuids[T any](uuids []string, db *gorm.DB) ([]T, error) {
	var (
		data []T
	)
	tx := db.Begin()
	err := tx.Where("uuid IN ? AND is_del=?", uuids, 0).Find(&data).Error
	if err != nil {
		tx.Rollback()
	} else {
		tx.Commit()
	}
	return data, err
}
